<%--
   help
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ attribute name="changeId" required="false" type="java.lang.String"
	description=""%>
<%@ attribute name="readOnly" required="false" type="java.lang.String"
	description=""%>
<%@ attribute name="afterSelected" required="false"
	type="java.lang.String" description=""%>
<div style="margin:10px;">
	<div id="riskSelectDiv"
		style="overflow:hidden;padding:0px;width:auto;min-height:0px;max-height:none;">
		<c:forEach var="category" items="${risk_category }">
			<li style="list-style-type:none;float:left;width:50%;"><h3>${category.name
					}</h3>
				<input id="${category.code }" vty="checkedSelected"
				vtv="${category.name }" style="display:none" /> <c:forEach
					var="entity" items="${risk_elementlist.content }">
					<c:choose>
						<c:when test="${category.code eq entity.categoryCode }">
							<div>
								<input type="radio" name="${category.name}" id="${entity.id }"
									onclick="setSelected('${category.code }')"
									tval="${entity.influence }" /> <label for="${entity.id }"
									style="font-size:14px;">${entity.name}</span>
							</div>
						</c:when>
					</c:choose>
				</c:forEach>
			</li>
		</c:forEach>
	</div>

</div>

<script type="text/javascript">
	$(function() {
		//根据changeId获取已经选择的项
		var id = '${changeId}';
		var readOnly = '${readOnly}';
		if (id) {
			$.ajax({
				async : false,
				url : "change/riskElement/getChgRiskElementList?sourceId=" + id,
				success : function(data) {
					for ( var i = 0; i < data.length; i++) {
						if ($("#" + data[i].id).click())
							;
						if (readOnly == "true") {
							$("[for='" + data[i].id + "']").css("color", "red");
						}
					}
				}
			});
		}

	});
	function setSelected(n) {
		$("#" + n).val("selected");
		var ifSuccess = true;
		$("[vty='checkedSelected']").each(function() {
			var t1 = $(this).val();
			if (t1 == "") {
				ifSuccess = false;
			}
		});
		if (ifSuccess) {
			var ids = "";
			var tvals = "";
			$('#riskSelectDiv input:radio:checked').each(function() {
				ids += this.id + ",";
				tvals += $(this).attr("tval") + ",";
			});
			ids = ids.substring(0, ids.length - 1);
			tvals = tvals.substring(0, tvals.length - 1);
			var returnObj = {
				ids : ids,
				tvals : tvals
			};
			${afterSelected};
		}

	}
	function getSelectIds() {
		var ifSuccess = true;
		var errMsg = "";
		$("[vty='checkedSelected']").each(function() {
			var t1 = $(this).val();
			if (t1 == "") {
				errMsg += "【" + $(this).attr("vtv") + "】必选选择一项！\n";
				ifSuccess = false;

				//isperp.alert($(this).attr("vtv")+"必选选择一项！");
			}
		});
		if (!ifSuccess) {
			alert(errMsg);
			return false;
		}

		var ids = "";
		var tvals = "";
		$('#riskSelectDiv input:radio:checked').each(function() {
			ids += this.id + ",";
			tvals += $(this).attr("tval") + ",";
		});
		ids = ids.substring(0, ids.length - 1);
		tvals = tvals.substring(0, tvals.length - 1);
		var returnObj = {
			ids : ids,
			tvals : tvals
		};
		return returnObj;
	}
</script>